
package com.jf.cloud.delivery.controller.app;

import com.jf.cloud.common.database.dto.PageDTO;
import com.jf.cloud.common.database.vo.PageVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.delivery.dto.TranscityFreeDTO;
import com.jf.cloud.delivery.model.TranscityFree;
import com.jf.cloud.delivery.service.TranscityFreeService;
import com.jf.cloud.delivery.vo.TranscityFreeVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 指定条件包邮城市项
 *
 * @author zz
 * @date 2020-12-07 15:10:01
 */
@RestController("appTranscityFreeController")
@RequestMapping("/transcity_free")
@Tag(name = "指定条件包邮城市项")
public class TranscityFreeController {

    @Autowired
    private TranscityFreeService transcityFreeService;

    @Autowired
    private MapperFacade mapperFacade;

    @GetMapping("/page")
    @Operation(summary = "获取指定条件包邮城市项列表" , description = "分页获取指定条件包邮城市项列表")
    public ServerResponseEntity<PageVO<TranscityFreeVO>> page(@Valid PageDTO pageDTO) {
        PageVO<TranscityFreeVO> transcityFreePage = transcityFreeService.page(pageDTO);
        return ServerResponseEntity.success(transcityFreePage);
    }

    @GetMapping
    @Operation(summary = "获取指定条件包邮城市项" , description = "根据transcityFreeId获取指定条件包邮城市项")
    public ServerResponseEntity<TranscityFreeVO> getByTranscityFreeId(@RequestParam Long transcityFreeId) {
        return ServerResponseEntity.success(transcityFreeService.getByTranscityFreeId(transcityFreeId));
    }

    @PostMapping
    @Operation(summary = "保存指定条件包邮城市项" , description = "保存指定条件包邮城市项")
    public ServerResponseEntity<Void> save(@Valid @RequestBody TranscityFreeDTO transcityFreeDTO) {
        TranscityFree transcityFree = mapperFacade.map(transcityFreeDTO, TranscityFree.class);
        transcityFree.setTranscityFreeId(null);
        transcityFreeService.save(transcityFree);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary = "更新指定条件包邮城市项" , description = "更新指定条件包邮城市项")
    public ServerResponseEntity<Void> update(@Valid @RequestBody TranscityFreeDTO transcityFreeDTO) {
        TranscityFree transcityFree = mapperFacade.map(transcityFreeDTO, TranscityFree.class);
        transcityFreeService.update(transcityFree);
        return ServerResponseEntity.success();
    }

    @DeleteMapping
    @Operation(summary = "删除指定条件包邮城市项" , description = "根据指定条件包邮城市项id删除指定条件包邮城市项")
    public ServerResponseEntity<Void> delete(@RequestParam Long transcityFreeId) {
        transcityFreeService.deleteById(transcityFreeId);
        return ServerResponseEntity.success();
    }
}
